package git.bankview.wl.report;

import java.util.*;
import java.sql.*;
import java.io.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;
import git.bankview.sl.report.ReportCommon;

import org.apache.log4j.Logger;

public class JasperPropertiesSetter
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(JasperPropertiesSetter.class);
	
	private static final String SQL_PURGER = "delete from dqreportprop where transid = ?";

	private static final String SQL_APPENDER = "insert into dqreportprop (transid, propname, propindex, strvalue) values (?, ?, ?, ?)";
	
	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] vPropName = oCtx.getActivityParameter().split(":");
		String oTransid = (String)oCtx.getField("transid");
		
		Connection oConn = DBConnectionFactory.getCoreConnection();
		try
		{
			PreparedStatement ps = oConn.prepareStatement(SQL_PURGER);
			ps.setString(1, oTransid);
			ps.executeUpdate();
			
			ps = oConn.prepareStatement(SQL_APPENDER);
			for (int i = 0; i < vPropName.length; ++i)
			{
				String[] vPropValue = (String[])oCtx.getField(vPropName[i]);
				
				for (int j = 0; null != vPropValue && j < vPropValue.length; ++j)
				{
					ps.setString(1, oTransid);
					ps.setString(2, vPropName[i]);
					ps.setInt(3, j);
					ps.setString(4, vPropValue[j]);
					ps.addBatch();
				}
			}
			
			ps.executeBatch();
		}
		finally
		{
			oConn.close();
		}
	}
}
